using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.IO;

namespace Index.Pages
{
    public class WikiPagesCollection
    {
		public WikiPagesCollection(string wikiRootDirectory)
		{
			rootDir = wikiRootDirectory;
			pages = getPages(rootDir);
		}

		private ArrayList pages = new ArrayList();
		private string rootDir;

		public string[] Pages
		{
			get { return pages.ToArray(typeof(string)) as string[]; }
		}

		private ArrayList getPages(string directory)
		{
			ArrayList result = new ArrayList();
			Stack stack = new Stack();

			stack.Push(new DirectoryInfo(directory));

			while (stack.Count > 0)
			{
				DirectoryInfo info = stack.Pop() as DirectoryInfo;

				DirectoryInfo[] dirs = info.GetDirectories();
				FileInfo[] files = info.GetFiles();

				foreach (FileInfo fi in files)
				{
					string fileName = fi.FullName;
					fileName = fileName.Replace(rootDir, "");
					result.Add(fileName);

                    /*
					if (result.Count % 1000 == 0)
					{
						Console.WriteLine(fileName);
					}*/
				}

				foreach (DirectoryInfo di in dirs)
				{
					stack.Push(di);
				}
			}

			return result;
		}
	}
}
